package com.tentact.servlets;

import com.tentact.service.DeptService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "insertDeptServlet", value = "/insertDeptServlet")
public class insertDeptServlet extends HttpServlet {
    DeptService service =new DeptService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //String Deptname =request.getParameter("departmentname");
        String Deptname =request.getParameter("departmentname").trim();
        System.out.println(Deptname);

        if (Deptname.equals("")) {
            String msg ="请输入要添加的部门名称";
            request.setAttribute("msg",msg);
            request.getRequestDispatcher("selectDeptServlet").forward(request,response);
        }else {

            if(service.insertDept(Deptname)!=1){
                System.out.println("添加失败");
            }else {
                request.getRequestDispatcher("selectDeptServlet").forward(request,response);
            }
        }





    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
